package com.baidumap.administrator.happystudy.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.ab.view.xtablayout.XTabLayout;
import com.baidumap.administrator.happystudy.fragment.Fragment_OrderList;
import com.baidumap.administrator.happystudy.fragment.Fragment_OrderList_Wei_Ping_Jia;
import com.baidumap.administrator.happystudy.R;
import com.baidumap.administrator.happystudy.adapter.ViewPagerAdapter;
import com.baidumap.administrator.happystudy.base.AppBaseActivity;

import butterknife.Bind;

/**
 * 描述：订单
 * 作者：xiaoxing on 17/4/10 22:41
 * 邮箱：2235445233@qq.com
 */
public class Order1Activity extends AppBaseActivity {

    @Bind(R.id.tabs)
    XTabLayout mTabLayout; 
    @Bind(R.id.viewPager)
    ViewPager mViewPager;
    public static final String[] tabTitle = new String[]{"已付款", "未付款", "已发货", "未评价"};

    private int mItem = 0;

    @Override
    public int bindLayout() {
        return R.layout.activity_order1;
    }

    @Override
    public void initView(View view) {
        super.initView(view);

        getBundleValue();
        initTabLayout(view);

    }

    private void getBundleValue() {

        Bundle bundle = getIntent().getExtras();

        if (bundle != null) {
            mItem = bundle.getInt("item");
        }
    }

    @Override
    public void doBusiness(Context mContext) {
        super.doBusiness(mContext);
        setHeaderBack();
        setHeaderTitle(R.string.order);

    }

    /**
     * 初始化水平滚动菜单
     *
     * @param view
     */
    private void initTabLayout(View view) {
        setupViewPager(mViewPager);
        mViewPager.setOffscreenPageLimit(mViewPager.getAdapter().getCount());
        // 设置ViewPager的数据等
        mTabLayout.setupWithViewPager(mViewPager);

        //适合很多tab
        //mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        //tab均分,适合少的tab
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        //tab均分,适合少的tab,TabLayout.GRAVITY_CENTER
        mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    }


    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

        Bundle data = new Bundle();

        Fragment newfragment = new Fragment_OrderList();
        data.putString("status", "1");
        data.putString("title", tabTitle[0]);
        newfragment.setArguments(data);
        adapter.addFrag(newfragment, tabTitle[0]);

        newfragment = new Fragment_OrderList();
        data = new Bundle();
        data.putString("status", "0");
        data.putString("title", tabTitle[1]);
        newfragment.setArguments(data);
        adapter.addFrag(newfragment, tabTitle[1]);


        newfragment = new Fragment_OrderList();
        data = new Bundle();
        data.putString("status", "2");
        data.putString("title", tabTitle[2]);
        newfragment.setArguments(data);
        adapter.addFrag(newfragment, tabTitle[2]);

        newfragment = new Fragment_OrderList_Wei_Ping_Jia();
        data = new Bundle();
        data.putString("status", "3");
        data.putString("title", tabTitle[3]);
        newfragment.setArguments(data);
        adapter.addFrag(newfragment, tabTitle[3]);

        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(mItem);

    }

}
